home *** CD-ROM | disk | FTP | other *** search
- #!xtk02 -f
- # Geoffrey Furnish -*-tcl-*-
- # 11 April 1994
- #
- # @> A script for using Tk to control xtk01, using the PLplot itcl interface.
- #
- # $Id: tk02,v 1.9 1994/07/24 07:42:58 mjl Exp $
- #
- # $Log: tk02,v $
- # Revision 1.9 1994/07/24 07:42:58 mjl
- # Eliminated "destroy ." in favor of "exit".
- #
- # Revision 1.8 1994/07/01 20:44:00 mjl
- # Modified to use startup proc plstdwin when configuring main window.
- #
- # Revision 1.7 1994/06/30 05:46:20 furnish
- # Another plot command in tk02 which invokes a private tclMatrix
- # extension for demo purposes. xtk02.c adds a new tclMatrix subcommand
- # "stuff", and tk02 exercises it. Dumb, but shows how it all works.
- #
- # Revision 1.6 1994/06/17 21:23:11 mjl
- # Removed option database settings since they were the same as those set
- # in the pldefaults proc.
- #
- # Revision 1.5 1994/06/16 21:56:32 mjl
- # Changed to new matrix declaration syntax. Locally declared matrices go
- # away automatically when the proc exits. It really works!
- #
- # Revision 1.4 1994/06/16 19:29:31 mjl
- # Changes to use new plframe/matrix API for functions that require array
- # arguments.
- #
- # Revision 1.3 1994/06/10 20:48:34 furnish
- # Do a lot more from Tcl. Still needs work, but waiting on the API
- # mirroring to catch up.
- #
- # Revision 1.2 1994/06/09 20:29:22 mjl
- # Changed to new improved megawidget instantiation method.
- #
- # Revision 1.1 1994/05/09 18:01:36 furnish
- # A new Tk demo, combining [incr Tcl] mega widget and the PLplot Tcl
- # extensions. Much more along these lines should be done.
- #
- ###############################################################################
-
- wm title . "x01c -- TK version"
- plstdwin .
-
- ###############################################################################
- # Set up the menubar and message widgets.
-
- frame .menu -relief raised -borderwidth 3
-
- button .menu.one -text "One" -command "myplot1"
- pack append .menu .menu.one {left expand fill}
-
- button .menu.two -text "Two" -command "myplot 2"
- pack append .menu .menu.two {left expand fill}
-
- button .menu.three -text "Three" -command "plot2"
- pack append .menu .menu.three {left expand fill}
-
- button .menu.four -text "Four" -command "myplot 4"
- pack append .menu .menu.four {left expand fill}
-
- button .menu.five -text "Five" -command "gumbyplot"
- pack append .menu .menu.five {left expand fill}
-
- button .menu.six -text "Six" -command "snoopy"
- pack .menu.six -side left -expand 1 -fill x
-
- button .menu.exit -text "Exit" -command "quit 0"
- pack append .menu .menu.exit {right expand fill}
-
- message .msg \
- -font -Adobe-helvetica-medium-r-normal--*-240* -aspect 200 \
- -width 500 -borderwidth 1 \
- -text "TK02: Demo \[incr Tcl\] interface to PLplot"
-
- PLXWin .plw -name foo
-
- pack append . .menu {top fillx} \
- .msg {top padx 5 pady 5 fill} \
- .plw {bottom expand fill}
-
- update
-
- tk_menuBar .menu .menu.one .menu.two .menu.three .menu.four .menu.exit
-
- ###############################################################################
- # Definitions of procedures used in this script.
-
- proc myplot1 {} {
- global xscale yscale xoff yoff
-
- set xscale 6
- set yscale 1
- set xoff 0
- set yoff 0
-
- plot1
- }
-
- # This is supposed to work just like the plot1() in x01c.c/xtk02.c
-
- proc plot1 {} {
- global xscale yscale xoff yoff
-
- matrix x1 float 10
- matrix y1 float 10
-
- for {set i 2; set n1 0} {$i < 60} {incr i 10; incr n1} {
- set x [expr $xoff + $xscale * ($i + 1) / 60]
- $x1 $n1 = $x
- $y1 $n1 = [expr $yoff + $yscale * pow($x,2)]
- }
-
- set n2 60
- matrix x2 float $n2
- matrix y2 float $n2
-
- for {set i 0} {$i < $n2} {incr i} {
- set x [expr $xoff + $xscale * ($i + 1) / $n2]
- $x2 $i = $x
- $y2 $i = [expr $yoff + $yscale * pow($x,2)]
- }
-
- set xmax [$x2 [expr $n2-1]]
- set ymax [$y2 [expr $n2-1]]
-
- .plw plcol 1
- .plw plenv $xoff $xmax $yoff $ymax 0 0
- .plw plcol 6
- .plw pllab "(x)" "(y)" "#frPLPLOT Example 1 - y=x#u2"
-
- # plot the data points
-
- .plw plcol 9
- .plw plpoin $n1 $x1 $y1 9
-
- # plot the data points
-
- .plw plcol 4
- .plw plline $n2 $x2 $y2
- }
-
- # This is supposed to work just like the plot2() in x01c.c/xtk02.c
-
- proc plot2 {} {
- .plw plcol 1
- .plw plenv -2 10 -.4 1.2 0 1
- .plw plcol 2
- .plw pllab "(x)" "sin(x)/x" "#frPLPLOT Example 1 - Sinc Function"
-
- # Fill up the array
-
- matrix x1 float 101
- matrix y1 float 101
-
- for {set i 0} {$i < 101} {incr i} {
- set x [expr ($i - 19.)/6.]
- $x1 $i = $x
- $y1 $i = 1
- if {$x != 0} { $y1 $i = [expr sin($x)/$x] }
- }
-
- .plw plcol 3
- .plw plline 101 $x1 $y1
- }
-
- proc gumbyplot {} {
- .plw plcol 1
- .plw plenv 0 1 0 1 0 0
- .plw plcol 6
- .plw pllab "(x)" "(y)" "#frPLplot Example 1 - y=1-2x+2x#u2"
-
- matrix x1 float 101
- matrix y1 float 101
-
- for {set i 0} {$i < 101} {incr i} {
- set x [expr $i * .01]
- $x1 $i = $x
- $y1 $i = [expr 1 - 2 * $x + 2 * $x * $x]
- }
-
- .plw plline 101 $x1 $y1
- }
-
- # This proc shows off the use of a matrix extension subcommand.
-
- proc snoopy {} {
- puts "Inside snoopy"
-
- matrix x float 101
- matrix y float 101
-
- for {set i 0} {$i < 101} {incr i} {
- set xx [expr $i * .01]
- $x $i = $xx
- }
-
- $y stuff
-
- .plw plcol 1
- .plw plenv 0 1 0 1 0 0
- .plw plcol 6
- .plw pllab "(x)" "(y)" "#frDemo of Matrix extension subcommand"
- .plw plline 101 $x $y
- }
-
- # Punch eject and hold onto your seat !!!
-
- proc quit a {
- exit
- }
-
- # Utility routine.
-
- proc dpos w {
- wm geometry $w +300+300
- }
-
- ###############################################################################
-